package t327.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import t327.pojo.font.LuiTableEntity;
import t327.pojo.until.Result;
import t327.pojo.views.SampleSheetListView;
import t327.service.iter.ISampleService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("SampleS")
public class SampleController {
        @Autowired
        private ISampleService iSampleService;

    @RequestMapping("getSempleInfo")
    @ResponseBody
    private LuiTableEntity getSempleInfo(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit") Integer pageSize) {
        List<SampleSheetListView> sampleSheetListViews1 = iSampleService.getAllSampleSheetList();
        LuiTableEntity luiTableEntity = new LuiTableEntity<SampleSheetListView>();
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<SampleSheetListView> menuPageInfo = new PageInfo<>(sampleSheetListViews1);
        List<SampleSheetListView> sampleSheetListViews = menuPageInfo.getList();
        long total = menuPageInfo.getTotal();
        if (sampleSheetListViews != null && sampleSheetListViews.size() > 0) {
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(sampleSheetListViews);
        } else {
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");
        }
        return luiTableEntity;

    }


    @RequestMapping("deleteSampleById")
    @ResponseBody
    public Result deleteSampleById(Long sampleSheetId) {
        int i = iSampleService.deleteSampleSheetListView(sampleSheetId);
        System.out.println(i + "修改结果");
        if (i > 0) {
            return Result.success();
        } else {
            return new Result(202, "删除失败", false, null);
        }

    }

    @RequestMapping("updateSample")
    @ResponseBody
    public String updateSample(@RequestBody Long sampleSheetId, Long auditStatus){
        return iSampleService.updateAuditStatus(sampleSheetId,auditStatus)>0?"success":"fail";
    }

//    @RequestMapping("getSemples")
//    @ResponseBody
//    public Map<String, Object> getSemples() {
//        Map<String, Object> response = new HashMap<>();
//
//        try {
//            Long auditStatus = iSampleService.getAuditStatus();
//            response.put("auditStatus", auditStatus);
//        } catch (Exception e) {
//            response.put("error", "Failed to retrieve audit status");
//        }
//
//        return response;
//    }
}



